package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import lombok.Getter;

import java.util.Objects;

@Getter
public enum RepeatTypeEnum {

    REPEAT_CANCEL(0, "noRepeat", "enum.repeatType.typeName.repeat_cancel"),

    REPEAT_SINGLE(1, "singleRepeat", "enum.repeatType.typeName.repeat_single"),

    REPEAT_ALL(2, "allRepeat", "enum.repeatType.typeName.repeat_all"),

    UNKNOWN(404, "enum.repeatType.typeName.unknown.typeName", "unknown")
    ;

    private Integer type;

    private String typeName;

    private String memo;

    RepeatTypeEnum(Integer type, String typeName, String memo) {
        this.type = type;
        this.typeName = typeName;
        this.memo = memo;
    }

    /**
     * 通过枚举 type 获得枚举
     *
     * @param type 类型
     * @return RepeatTypeEnum
     */
    public static RepeatTypeEnum getByType(Integer type) {
        for (RepeatTypeEnum cacheCode : values()) {
            if (Objects.equals(cacheCode.getType(), type)) {
                return cacheCode;
            }
        }
        return UNKNOWN;
    }

    public String getTypeName() {
        return I18nMessageUtil.getMessage(typeName);
    }
}
